package com.demo;

import org.openjdk.jol.info.ClassLayout;

/**
 * java 对象内存布局测试
 * @author shenguangyang
 */
public class JavaObjectLayoutExample {
    static final JavaObjectLayout javaObjectLayout = new JavaObjectLayout();
    private static class JavaObjectLayout {
        String data = "hello";
    }
    public static void main(String[] args) {
        System.out.println(ClassLayout.parseInstance(javaObjectLayout).toPrintable());
        System.out.println("hashCode: " + javaObjectLayout.hashCode());
        System.out.println(ClassLayout.parseInstance(javaObjectLayout).toPrintable());
        synchronized (javaObjectLayout) {
            System.out.println(ClassLayout.parseInstance(javaObjectLayout).toPrintable());
        }
        System.out.println(ClassLayout.parseInstance(javaObjectLayout).toPrintable());
    }     
}
